"""
工具函数模块
"""

import platform
from typing import List

def get_system_fonts() -> List[str]:
    """
    获取系统字体列表
    :return: 字体名称列表
    """
    # 这里简化实现，实际应用中可能需要更复杂的逻辑
    # Windows和macOS获取系统字体的方式不同

    common_fonts = [
        "宋体", "黑体", "楷体", "仿宋",
        "微软雅黑", "Arial", "Times New Roman",
        "Courier New", "Verdana", "Tahoma"
    ]

    if platform.system() == "Windows":
        common_fonts.extend(["SimSun", "SimHei", "KaiTi", "FangSong"])
    elif platform.system() == "Darwin":  # macOS
        common_fonts.extend(["PingFang SC", "Hiragino Sans GB", "Heiti SC"])

    return sorted(common_fonts)

def is_wps_installed() -> bool:
    """
    检查是否安装了WPS
    :return: 是否安装
    """
    try:
        if platform.system() == "Windows":
            import winreg
            try:
                key = winreg.OpenKey(
                    winreg.HKEY_LOCAL_MACHINE,
                    r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\wpsoffice.exe"
                )
                winreg.CloseKey(key)
                return True
            except WindowsError:
                return False
        elif platform.system() == "Darwin":  # macOS
            return os.path.exists("/Applications/WPS Office.app")
        else:
            return False
    except:
        return False

def ensure_dir_exists(path: str):
    """
    确保目录存在
    :param path: 目录路径
    """
    os.makedirs(path, exist_ok=True)

def get_temp_path() -> str:
    """
    获取临时目录路径
    :return: 临时目录路径
    """
    import tempfile
    return tempfile.gettempdir()

def get_chinese_font_sizes():
    """返回中文印刷标准字号与磅值的映射关系"""
    return {
        "初号": 42,
        "小初": 36,
        "一号": 26,
        "小一": 24,
        "二号": 22,
        "小二": 18,
        "三号": 16,
        "小三": 15,
        "四号": 14,
        "小四": 12,
        "五号": 10.5,
        "小五": 9,
        "六号": 7.5,
        "小六": 6.5,
        "七号": 5.5,
        "八号": 5
    }

def get_font_size_options():
    """获取字号选项列表"""
    sizes = get_chinese_font_sizes()
    # 中文标准字号 + 常用磅值
    return list(sizes.keys()) + [str(i) for i in range(8, 73)]
